package com.geline.alisms;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnProperty(prefix = "sms", name = "active")
@ConditionalOnMissingBean(SmsSender.class)
@EnableConfigurationProperties({ AliSmsProperties.class })
public class AliSmsAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean
    SendPostProcessor initSendPostProcessor() {
        return new DefaultSendPostProcessor();
    }

    @Bean
    @ConditionalOnProperty(prefix = "sms", name = "active", havingValue = "ali")
    SmsSender aliSmsSender(AliSmsProperties properties, SendPostProcessor sendPostProcessor) {
        return new AliSmsSender(properties, sendPostProcessor);
    }

    @Bean
    @ConditionalOnProperty(prefix = "sms", name = "active", havingValue = "log")
    SmsSender logSmsSender(AliSmsProperties properties, SendPostProcessor sendPostProcessor) {
        return new DefaultSmsSender();
    }
}
